package com.whj.serviceverificationcode.controller;

import com.whj.internalcommon.dto.ResponseResult;
import com.whj.internalcommon.response.NumberCodeResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: wanghaijun
 * @Date: 2022/12/26 - 12 - 26 - 14:49 
 * @Description: com.whj.serviceverificationcode.controller
 */

@RestController
public class NumberCodeController {

    @GetMapping("/numberCode/{size}")
    public ResponseResult numberCode(@PathVariable("size") int size) {
        System.out.println("size = " + size);

        //生成验证码
        double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10, size - 1));
        int resultInt = (int) mathRandom;

        System.out.println("远程提供的验证码 = " + resultInt);
        //定义返回值
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode(resultInt);
        return ResponseResult.success(response);
    }

}
